package org.makcro.sms.services.chat.base.senders;

import java.text.MessageFormat;

import org.apache.log4j.Logger;
import org.makcro.sms.services.chat.model.Question;

import com.klikmee.sms.cef.services.Service;

/**
 * ************************************************
 * <p>
 * Default implementation of {@link MessageSender} interface. Uses single charging code to send messages
 * </p>
 * 
 * @author makcro
 * 
 */
public class SimpleMessageSenderImpl extends AbstractMessageSender {

	/**
	 * Logger instance
	 */
	private Logger logger = Logger.getLogger(SimpleMessageSenderImpl.class);

	/**
	 * Charging and service props
	 */

	private Long chargingId;
	private Long serviceId;

	public SimpleMessageSenderImpl() {
		super();
		logger.info("SimpleMessageSender initialized.");
	}

	@Override
	public Long sendMessage(String messageText, Long coreReferenceId, Object data) {
		// cast additional data to question obj
		Question question = (Question) data;

		Long coreResponseId = this.coreAdapter.sendMessage(chargingId, serviceId, Service.SERVICE_FLAG_SEMANTIC_OK, coreReferenceId, messageText);
		persistAnswer(question, messageText, coreResponseId, true);

		logger.info(MessageFormat.format("Created answer with core id = [{0}]", coreResponseId));
		return coreResponseId;

	}

	public void setChargingId(Long chargingId) {
		this.chargingId = chargingId;
	}

	public void setServiceId(Long serviceId) {
		this.serviceId = serviceId;
	}

}
